package com.ag.lwc.dao;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;
import com.ag.bean.TbLogType;
import com.ag.common.IDUtil;
import com.ag.dao.TbLogTypeDAO;

public class MyTbLogTypeDAO extends TbLogTypeDAO {
	public TbLogType findById(String id)
	{
		System.out.println("MyTbLogTypeDAO : 传入来的id："+id);
		TbLogType logType=null;
		Session session = this.getSessionFactory().openSession();
		logType = (TbLogType) session.get(TbLogType.class, id);
		System.out.println("MyTbLogTypeDAO :日志类型id： "+logType.getLtId());
		session.close();
		return logType;
	}
	public List findAll()
	{
	
		return getHibernateTemplate().executeFind(new HibernateCallback(){

						@Override
						public Object doInHibernate(Session session) throws HibernateException, SQLException 
							{
							   	Criteria crit = session.createCriteria(TbLogType.class);
							   //	crit.add(Restrictions.or(Restrictions.isNull("a"),Restrictions.not(Restrictions.eq("a",IDUtil.DELETE))));
								crit.addOrder(Order.asc("ltId"));
								System.out.println("*******************查了出来没有？********************");
							   	return crit.list();
							}});
		
	}
	public void delete(final String id)
	{
		this.getHibernateTemplate().execute(new HibernateCallback(){

			@Override
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException
			{
				TbLogType tbLogType = (TbLogType) session.get(TbLogType.class, id);
			//	tbLogType.setA(IDUtil.DELETE);
				
				return null;
			}});
	}

}
